package cn.ssq.service.impl;

import cn.ssq.dao.SampleInfoMapper;
import cn.ssq.dao.SampleToxinMapper;
import cn.ssq.domain.SampleToxin;
import cn.ssq.service.SampleToxinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SampleToxinServiceImpl implements SampleToxinService {
    @Autowired
    private SampleToxinMapper sampleToxinMapper;
    @Autowired
    private SampleInfoMapper sampleInfoMapper;
    @Override
    public int addSampleToxin(SampleToxin sampleToxin) {
        return sampleToxinMapper.insert(sampleToxin);
    }

    /**
     * 修改毒素信息
     * @return
     */
    @Override
    public int updateToxin(Integer sampleId) {
           int i = sampleToxinMapper.updateByPrimaryKey(sampleId);
        return i;
    }

    //添加毒素
    @Override
    public int insertTxon(Integer sid,Integer[] toxinId, String[] toxinCount){
        int i = 0;
        if (toxinId!=null&&toxinId.length>1&&toxinCount!=null&&toxinCount.length>1){
            for (int k = 0; k < toxinCount.length; k++) {
                i = sampleToxinMapper.insertToxn(toxinId[k],toxinCount[k],sid);
            }
        }else {
            i = sampleToxinMapper.insertToxn(toxinId[0],toxinCount[0],sid);
            return i;
        }
        return i;
    }

    @Override
    public List<SampleToxin> findBySampleInfoId(Integer sampleId) {

        return sampleToxinMapper.selectBySampleInfoId(sampleId);
    }

    @Override
    public Integer[] selectByToxin(Integer sampleId) {

        Integer[] integers = sampleToxinMapper.selectByToxinId(sampleId);
        return integers;
    }

    @Override
    public int selectIdT(String toxinN) {
        return 0;
    }


}
